package org.qianji.goosql.table;

import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * 简单表，用于表示数据库中真实存在的表、视图。
 * 
 * @author gmz
 * 
 */
public class SimpleTable extends AbstractTable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -7355309359835986335L;

	private String tableName;

	/**
	 * 根据表名构造简单表
	 * 
	 * @param tableName
	 *            {@link java.lang.String String} 表名
	 */
	public SimpleTable(String tableName) {
		super();
		if (tableName == null || tableName.isEmpty()) {
			throw new NullPointerException("tableName can't be null or empty");
		}
		this.tableName = tableName;
	}

	@Override
	public String toSql() {
		return tableName;
	}

	@Override
	public String getTable() {
		return tableName;
	}

	@Override
	public String getTableName() {
		return tableName;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Object> getPlacedParameters() {
		return Collections.EMPTY_LIST;
	}

	@SuppressWarnings("unchecked")
	@Override
	public Map<String, Object> getNamedParameters() {
		return Collections.EMPTY_MAP;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null || !(obj instanceof SimpleTable)) {
			return false;
		}
		if (tableName.equals(((SimpleTable) obj).getTable())) {
			return true;
		}
		return false;
	}

	@Override
	public int hashCode() {
		int hc = 37 * 17 + tableName.hashCode();
		return hc;
	}

	@Override
	public String toString() {
		return toSql();
	}

}
